[HOTE-983] feat: Generate Notification: Order Dispatched#316
[HOTE-983] feat: Generate Notification: Order Dispatched#316
Conversation
There was a problem hiding this comment.
Pull request overview
Adds “Order Dispatched” notification generation to the order-status ingestion flow, extending the lambdas package with new message-building and DB/audit utilities and wiring local infra env vars to support local execution.
Changes:
- Enqueue a Notify message to SQS when an order receives its first
DISPATCHEDstatus, and write a notification audit entry. - Introduce
NotifyEventCode.OrderDispatchedplus supportingNotifyMessageBuilder,PatientDbClient, andNotificationAuditDbClient. - Update local Terraform to provide queue URL and base URL env vars to
order-status-lambda.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| local-environment/infra/main.tf | Adds env vars for notify queue URL and home test base URL for local order-status lambda. |
| lambdas/src/order-status-lambda/notify-message-builder.ts | Builds the ORDER_DISPATCHED notify payload (recipient lookup + personalisation). |
| lambdas/src/order-status-lambda/notify-message-builder.test.ts | Unit tests for message construction, date formatting, and base URL normalisation. |
| lambdas/src/order-status-lambda/init.ts | Wires new DB clients, SQS client, message builder, and env var retrieval into DI. |
| lambdas/src/order-status-lambda/init.test.ts | Extends init wiring tests for the new dependencies/env vars. |
| lambdas/src/order-status-lambda/index.ts | Sends dispatched notification on first DISPATCHED status; inserts notification audit entry. |
| lambdas/src/order-status-lambda/index.test.ts | Adds handler tests covering notification send / suppression behavior. |
| lambdas/src/lib/types/notify-message.ts | Adds OrderDispatched event code to the notify message model. |
| lambdas/src/lib/db/patient-db-client.ts | Adds DB lookup for notify recipient data (NHS number + DOB) by patient UID. |
| lambdas/src/lib/db/patient-db-client.test.ts | Unit tests for patient recipient lookup and missing-record behavior. |
| lambdas/src/lib/db/order-status-db.ts | Adds isFirstStatusOccurrence() helper used to gate first-time DISPATCHED notifications. |
| lambdas/src/lib/db/order-status-db.test.ts | Adds tests for isFirstStatusOccurrence(); improves DBClient typing in test setup. |
| lambdas/src/lib/db/notification-audit-db-client.ts | Adds insert helper for notification_audit table entries. |
| lambdas/src/lib/db/notification-audit-db-client.test.ts | Unit tests for audit insert behavior and zero-row failure case. |
…of github.com:NHSDigital/hometest-service into feature/hote-983/generate-notify-for-order-dispatched
| const isFirstDispatched = await orderStatusDb.isFirstStatusOccurrence( | ||
| orderId, | ||
| OrderStatusCodes.DISPATCHED, | ||
| ); | ||
|
|
||
| if (!isFirstDispatched) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
One for me to check if we should need to bother checking. I keep meaning to do this but forget to. Maybe one for @ronanoconnor1 to input on as well. Should we allow for multiple of the same or out of sync status updates?
There was a problem hiding this comment.
Well, the implementation may change in this case, because I also thought about it when making 985, because there we ignore adding a duplicate for order status, but we still add for test status, so this check there may result in sending many notifications if someone send the complete result many times.
|



Description
https://nhsd-jira.digital.nhs.uk/browse/HOTE-983
Context
Type of changes
Checklist
Sensitive Information Declaration
To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.